package com.xindaoapp.happypet.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPool {

	/** 图片加载线程池 */
	private static ExecutorService mImageFetchThreadPool;

	/** 线程池锁 */
	private static Object mLock = new Object();

	/**
	 * 给线程池加入线程任务
	 */
	public static void addRunnable(Runnable runnable) {
		Thread thread = new Thread(runnable);
		thread.setDaemon(true);
		synchronized (mLock) {
			if (mImageFetchThreadPool == null) {
				mImageFetchThreadPool = Executors.newCachedThreadPool();
			}
			mImageFetchThreadPool.execute(thread);
		}
	}

	/**
	 * 
	 * 关闭线程池
	 */
	public static void shutdownNow() {
		synchronized (mLock) {
			if (mImageFetchThreadPool != null) {
				mImageFetchThreadPool.shutdown();
				mImageFetchThreadPool = null;
			}
		}
	}
}
